package hellfire.platform.screens;

import android.opengl.Matrix;
import hellfire.game.Game;
import hellfire.platform.input.GameListener;
import hellfire.system.R;
import hellfire.system.graphics.GLColor;
import hellfire.system.graphics.GLDrawable;
import hellfire.system.graphics.GLImage;
import hellfire.system.graphics.GLRelVec2;
import hellfire.system.graphics.GLRenderer;
import hellfire.system.graphics.GLString;
import hellfire.system.graphics.GLVec2;

public class ChickenScreen extends AbstractGameScreen 
{
	private GLImage background;
	
	private Game game;
	
	private GLString FPS;
	
	public ChickenScreen()
	{
		game = new Game();
		
		addItem(new GameListener(game, new GLVec2(0.9, 0.9), new GLVec2(0.1, 0.1)));
		
		FPS = new GLString(R.drawable.basefont, "FPS", new GLRelVec2(0.5,0.95), new GLRelVec2(0.1,0.1));
        FPS.setTextColor(GLColor.DARKGREEN);
        
	}
	
	
	public long last_logtime = 0;
	public int frames = 0;
	public void logFrame()
	{
		frames++;
		long cur_time = System.nanoTime();
		if(cur_time - last_logtime > 1*1000000000)
		{
			last_logtime = cur_time;
			FPS.setString("FPS: " + frames, true);
			frames = 0;
		}
	}
	
	@Override
	public void draw(float[] matrix)
	{
		logFrame();
		GLRenderer.pushMatrix(matrix);
		Matrix.scaleM(matrix, 0, 0.9f, 0.9f, 1);
		Matrix.translateM(matrix, 0, 0.1f, 0.1f, 0);
		super.draw(matrix);
		game.getRenderer().draw(matrix);
		GLRenderer.popMatrix(matrix);
		FPS.draw(matrix);
		
		
	}
	
	@Override
	public void gameFrame() 
	{
		game.gameFrame();
	}

	@Override
	public void onBack() 
	{
		// TODO Auto-generated method stub

	}
	

}
